package com.lcj.controller;

import com.lcj.vo.UserVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;

import javax.servlet.http.HttpServletRequest;

@Controller
@SessionAttributes("userVo")
@RequestMapping("/sessionattr")
public class TestSessionAttributes {

    @RequestMapping("/addattr")
    public String  addattr(HttpServletRequest request)
    {
        UserVo userVo = new UserVo("zhag",123);
        request.getSession().setAttribute("userVo",userVo);
        return "success";
    }

    @RequestMapping("/getattr")
    public String getattr(@ModelAttribute UserVo userVo, SessionStatus sessionStatus){
        System.out.println(userVo.getUsername());
        sessionStatus.isComplete();
        return "success";
    }

    @RequestMapping("/methodmodel")
    @ModelAttribute("name")
    public String test(@RequestParam(required = false) String name){
        return name;
    }


}
